home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------
-
- AOCE Post Office Protocol (POP) / Simple Mail Transfer Protocol (SMTP)
- Mail Service Access Module
-
- written by Steve Falkenburg-- MacDTS
- ©1991-1993 Apple Computer, Inc.
-
- --------------
- change history
- --------------
-
- SJF 02/19/93 update for beta build b1
- SJF 10/29/92 update to a11 a11
- SJF 06/08/92 update to a8 a8
- SJF 02/15/92 first working version a4.5
- SJF 10/16/91 initial coding a3
-
- ---------------------------------------------------------------------*/
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __OCE__
- #include <OCE.h>
- #endif
-
- #ifndef __OCEMAIL__
- #include <OCEMail.h>
- #endif
-
- #ifndef __OCEERRORS__
- #include <OCEErrors.h>
- #endif
-
- #include <MacTCPCommonTypes.h>
-
- #include "const.h"
- #include "gwerrors.h"
- #include "mytypes.h"
- #include "globals.h"
- #include "utils.h"
- #include "gatewaystuff.h"
-
- #include "errorhandling.h"
-
- #define kFirstTCPError -23049
- #define kLastTCPError -23000
-
- #define kFirstAOCEError -1999
- #define kLastAOCEError -1500
- #define kFirstAOCEErrorToo -15199
- #define kLastAOCEErrorToo -15000
-
-
- void DoError(OSErr err)
- {
- MailErrorLogEntryInfo ml;
- PMSAMLogErrorPB msamBlock;
- MSAMSlotID slotID;
- SlotSpec *slotSpec;
-
- #ifdef kDEBUG
- DebugStr("\pAN ERROR HAS OCCURRED");
- #endif
-
- if (gAOCEInited==false) {
- NoAOCEError(err);
- return;
- }
-
- slotSpec = GetSlotSpecFromID(1);
-
- slotID = 0; // non-slot specific
- ml.version = kMailErrorLogEntryVersion;
- ml.errorType = 0;
- ml.errorCode = 0;
- ml.errorResource = 0;
- ml.actionResource = 0;
-
- if (err>=kFirstTCPError && err<=kLastTCPError) {
- // MACTCP ERROR (warning)
- ml.errorType = kMailELEWarning;
- ml.errorCode = kMailMSAMErrorCode;
- ml.errorResource = kMacTCPError;
- if (slotSpec)
- slotID = slotSpec->slotID; // we only have 1 slot- make it easy on ourselves
- }
- else if (((err>=kFirstAOCEError) && (err<=kLastAOCEError)) ||
- ((err>=kFirstAOCEErrorToo) && (err<=kLastAOCEErrorToo))) {
- // AOCE ERROR (warning)
- ml.errorType = kMailELEWarning;
- ml.errorCode = kMailMSAMErrorCode;
- ml.errorResource = kAOCEError;
- }
- else if ((err>=kFirstNonCorrectableError) && (err<=kLastNonCorrectableError)) {
- // NON-CORRECTABLE ERROR (error)
- ml.errorType = kMailELEError;
- ml.errorCode = kMailMSAMErrorCode;
- ml.errorResource = err;
- }
- else if ((err>=kFirstCorrectableError) && (err<=kLastCorrectableError)) {
- // CORRECTABLE ERROR (correctable)
- ml.errorType = kMailELECorrectable;
- ml.errorCode = kMailMSAMErrorCode;
- ml.errorResource = err;
- ml.actionResource = err;
- if (err!=kMacTCPNotAvailable)
- if (slotSpec)
- slotID = slotSpec->slotID; // we only have 1 slot- make it easy on ourselves
- }
- else {
- // MISC TOOLBOX ERRORS (warning)
- ml.errorType = kMailELEWarning;
- ml.errorCode = kMailMSAMErrorCode;
- ml.errorResource = kToolboxError;
- }
-
- msamBlock.logEntry = &ml;
- msamBlock.msamSlotID = slotID;
-
- err = PMSAMLogError((MSAMParam *)&msamBlock);
- #ifdef kDEBUG
- if (err!=noErr)
- DebugStr("\pERROR LOG FAILED");
- #endif
- }
-
-
- void NoAOCEError(OSErr err)
- {
- Str255 errStr;
- Str255 errNumStr;
-
- if (err==noErr)
- return;
-
- if (err>0)
- GetIndString(errNumStr,128,err); // positive errors indicate specific app errors
- else
- NumToString(err,errNumStr);
-
- pstrcpy(errStr,"\pAn error has occurred: ");
- pstrcat(errStr,errNumStr);
-
- #ifdef kDEBUG
- DebugStr(errStr);
- #endif
-
- Notify(errStr);
-
- }
-
-
- void Notify(StringPtr string)
- {
- NMRecPtr nm;
- StringPtr strPtr;
-
- nm = (NMRecPtr)NewPtrSys(sizeof(NMRec)); // put in system heap, since we're going away
- if (MemError()!=noErr)
- return;
- strPtr = (StringPtr)NewPtrSys(string[0]);
- if (MemError()!=noErr)
- return;
- BlockMove(string,strPtr,string[0]+1);
-
- nm->qType = nmType;
- nm->nmMark = 0;
- nm->nmIcon = nil;
- nm->nmSound = nil;
- nm->nmStr = strPtr;
- nm->nmResp = (NMProcPtr)-1L; // close enough for memory deallocation, otherwise we need to copy code into sys heap.
- NMInstall(nm);
- }
-
-
- // used to track error retries on a slot
- //
- // if you exceed the number of retries allowed on the same error, this
- // function will report the error to the toolbox, otherwise, it will
- // track the retries until you reach the maximum
- //
- OSErr RetrySlotError(OSErr err,SlotSpec *slot,Boolean forPut)
- {
- if (err==noErr) {
- // reset counters if no error
- if (forPut) {
- slot->retryPutError = noErr;
- slot->retryPut = 0;
- }
- else {
- slot->retryGetError = noErr;
- slot->retryGet = 0;
- }
- }
- else {
-
- #ifdef kDEBUG
- DebugStr("\pAN ERROR HAS OCCURRED");
- #endif
-
- if (forPut) {
- if (slot->retryPutError!=err) {
- // need to report *both* errors here, since they are different
- // old error is reported directly, new error through return
- if (slot->retryPutError!=noErr)
- DoError(slot->retryPutError);
- slot->retryPut = 0;
- slot->retryPutError = err;
- }
- else
- slot->retryPut++;
-
- // have we passed max retries?
-
- if (slot->retryPut >= kAllowedRetries) {
- slot->retryPutError = noErr;
- slot->retryPut = 0;
- }
- else
- err = noErr;
- }
- else {
- if (slot->retryGetError!=err) {
- // need to report *both* errors here, since they are different
- // old error is reported directly, new error through return
- if (slot->retryGetError!=noErr)
- DoError(slot->retryGetError);
- slot->retryGet = 0;
- slot->retryGetError = err;
- }
- else
- slot->retryGet++;
-
- // have we passed max retries?
-
- if (slot->retryGet >= kAllowedRetries) {
- slot->retryGetError = noErr;
- slot->retryGet = 0;
- }
- else
- err = noErr;
- }
- }
- return err;
- }